﻿//------------------------------------------------------------------------------
// System Name:    Customer Service Platform
// Component:      CIS Domestic DepartmentManagement
// Created By:     Samara Jiang (samaraj@wicresoft.com)
// Created Date:   2011-1-30
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASBCC.Business;
using ASBCC.Business.CIS;
using ASBCC.Database.EntityFramework;

namespace BEGDC.CC.Web.CIS2.Domestic.Admin
{
    /// <summary>
    ///  CIS Domestic DepartmentManagement
    /// </summary>
    public partial class DepartmentManagement : EntityPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected override EntityDataSource EntitySource
        {
            get { return this.edsCoustomerDepartment; }
        }

        protected override TextBox EntitySearchTxt
        {
            get { return this.SearchText; }
        }

        protected override Button EntityAddBtn
        {
            get { return this.BtnAdd; }
        }

        protected override Button EntitySearchBtn
        {
            get { return this.Searchbtn; }
        }
        protected override Button EntityClearBtn
        {
            get { return this.Cleanbtn; }
        }

        protected override GridView EntityGrid
        {
            get { return this.gvDepartment; }
        }

        protected override DetailsView EntityDetails
        {
            get { return this.dvDepartment; }
        }

        protected override void OnEntityDisabling(int entityKey)
        {
            if (!DepartmentManagementHelper.SetDepartmentDisabled(entityKey))
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript'>alert('" + Resources.Messages.DeleteDepartmentFailedTips + "');</script>");
            else
            {
                GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CID, "CustomerDepartment disabled. id=" + entityKey + ", name=" + DepartmentManagementHelper.getName(entityKey));
                GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CIO, "CustomerDepartment disabled. id=" + entityKey + ", name=" + DepartmentManagementHelper.getName(entityKey));
            }
        }

        protected override string GetEntityWhereExpression(string keyword)
        {
            return "(it.Name like N'%" + keyword + "%'"
                 + " or it.Description like N'%" + keyword + "%')";
        }

        protected override void OnEntityInserting(EntityDataSourceChangingEventArgs e)
        {

        }

        protected override void OnEntityUpdating(EntityDataSourceChangingEventArgs e)
        {

        }


        protected void edsCoustomerDepartment_Inserted(object sender, EntityDataSourceChangedEventArgs e)
        {
            var dc = e.Context;
            var department = e.Entity as CustomerDepartment;

            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CID, "Department inserted. id=" + department.DepartmentID + ", name=" + department.Name + "; Comment=" + department.Description);
            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CIO, "Department inserted. id=" + department.DepartmentID + ", name=" + department.Name + "; Comment=" + department.Description);
        }

        protected void edsCoustomerDepartment_Updated(object sender, EntityDataSourceChangedEventArgs e)
        {
            var dc = e.Context;
            var department = e.Entity as CustomerDepartment;

            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CID, "Department updated. id=" + department.DepartmentID + ", name=" + department.Name + "; Comment=" + department.Description);
            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CIO, "Department updated. id=" + department.DepartmentID + ", name=" + department.Name + "; Comment=" + department.Description);
        }


    }
}
